package com.iafme.service.impl;

import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.operator.Contain;
import cn.zhxu.bs.util.MapUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iafme.dto.req.CourseReqDTO;
import com.iafme.dto.res.CourserResDTO;
import com.iafme.mapper.CourseMapper;
import com.iafme.model.Course;
import com.iafme.service.CourseService;
import com.systemframework.util.SearchUtl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author summer
 * @version 1.0
 * @date 2025/1/7 10:08
 */
@Service
@Transactional(rollbackFor = Exception.class)
@AllArgsConstructor
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    private final BeanSearcher beanSearcher;

    @Override
    public Page<CourserResDTO> lists(CourseReqDTO courseReqDTO) {
        Map<String, Object> build = MapUtils.builder().page(courseReqDTO.getPageNum() - 1, courseReqDTO.getPageSize())
                .field(CourserResDTO::getName, courseReqDTO.getName()).op(Contain.class)
                .field(CourserResDTO::getProjectName, courseReqDTO.getProjectName()).op(Contain.class)
                .field(CourserResDTO::getLevelName, courseReqDTO.getLevelName()).op(Contain.class)
                .field(CourserResDTO::getShowingsName, courseReqDTO.getShowingsName()).op(Contain.class).build();

        return SearchUtl.searchDataList(courseReqDTO.getPageNum(),courseReqDTO.getPageSize(),beanSearcher.search(CourserResDTO.class,build));
    }
}
